package Eyjafjalla.patch;

import Eyjafjalla.save.EyjafjallaSave;
import Eyjafjalla.save.EyjafjallaSaveAndContinue;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePostfixPatch;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.saveAndContinue.SaveAndContinue;
import com.megacrit.cardcrawl.saveAndContinue.SaveFile;

public class SaveAndContinuePatch {
    public static EyjafjallaSave eyjafjallaSave = new EyjafjallaSave();

    //保存和加载
    @SpirePatch(clz = SaveAndContinue.class, method = "save")
    public static class SavePatch {
        @SpirePostfixPatch
        public static void Postfix(SaveFile save) {
            eyjafjallaSave.onSave();
            EyjafjallaSaveAndContinue.saveEyjafjalla(eyjafjallaSave);
        }
    }

    @SpirePatch(clz = SaveAndContinue.class, method = "loadSaveFile",paramtypez = {AbstractPlayer.PlayerClass.class})
    public static class LoadPatch {
        @SpirePostfixPatch
        public static SaveFile Postfix(SaveFile _ret, AbstractPlayer.PlayerClass c) {
            EyjafjallaSave e = EyjafjallaSaveAndContinue.loadEyjafjalla(c);
            if(e!=null){
                eyjafjallaSave = e;
                eyjafjallaSave.onLoad();
            }
            return _ret;
        }
    }

    @SpirePatch(clz = SaveAndContinue.class,method = "deleteSave")
    public static class DeletePatch{
        @SpirePostfixPatch
        public static void Postfix(AbstractPlayer p){
            eyjafjallaSave.onDelete();
            EyjafjallaSaveAndContinue.deleteEyjafjalla(p.chosenClass);
        }
    }
}
